package com.xpgk.mvc.right;

import com.jfinal.log.Log;
import com.xpgk.annotation.Table;
import com.xpgk.mvc.base.BaseModel;
import com.xpgk.plugin.ParamInitPlugin;
import com.xpgk.tools.ToolCache;

/**
 * 系统功能model
 */
@SuppressWarnings("unused")
@Table(tableName = Right.table_name)
public class Right extends BaseModel<Right> {

	private static final long serialVersionUID = 6761767368352810428L;

	private static final Log log = Log.getLog(Right.class);

	public static final Right dao = new Right().dao();

	/**
	 * 表名称
	 */
	public static final String table_name = "sys_right";

	/**
	 * 字段描述：该条数据添加人员is  字段类型：character varying 长度：32
	 */
	public static final String column_createId = "createId";
	/**
	 * 字段描述：该条数据添加时间  字段类型：datetime 长度：0
	 */
	public static final String column_createDate = "createDate";
	/**
	 * 字段描述：该条数据更新人员id  字段类型：character varying 长度：100
	 */
	public static final String column_updateId = "updateId";
	/**
	 * 字段描述：该条数据更新时间  字段类型：datetime 长度：0
	 */
	public static final String column_updateDate = "updateDate";
	
	/**
	 * 字段描述：主键 字段类型：character varying 长度：32
	 */
	public static final String column_ids = "ids";

	/**
	 * 字段描述：名称 字段类型：character varying 长度：25
	 */
	public static final String column_name = "name";

	/**
	 * 字段描述：uri 字段类型：character varying 长度：200
	 */
	public static final String column_uri = "uri";

	/**
	 * 字段描述：层级int 长度：2
	 */
	public static final String column_level = "levelnum";

	/**
	 * 字段描述: 是否父节点 string 长度：5
	 */
	public static final String column_isparent = "isparent";

	/**
	 * 字段描述: 是否展开 string 长度：5
	 */
	public static final String column_isopen = "isopen";

	/**
	 * 字段描述: 父节点ids string 长度：32
	 */
	public static final String column_parentids = "parentids";

	/**
	 * 字段描述: 序号 string 长度：11
	 */
	public static final String column_orderid = "orderid";

	/**
	 * 字段描述：图标 string 长度：50
	 */
	public static final String column_icon = "icon";

	/**
	 * 字段描述：是否分页 字段类型：character 长度：1
	 */
	public static final String column_splitpage = "splitpage";

	/**
	 * 字段描述：是否需要权限验证 字段类型：character 长度：1
	 */
	public static final String column_privilegess = "privilegess";

	/**
	 * 字段描述：状态 string 长度：1
	 */
	public static final String column_status = "status";

	/**
	 * sqlId : sys.right.paging 描述：查询所有权限
	 */
	public static final String sqlId_paging = "sys.right.paging";

	/**
	 * 描述：查询一级菜单
	 */
	public static final String sqlId_one_menu = "sys.right.one_menu";

	/**
	 * 描述：查询二级菜单
	 */
	public static final String sqlId_two_menu = "sys.right.two_menu";

	/**
	 * 描述：根据uri查询
	 */
	public static final String sqlId_uri = "sys.right.uri";

	/**
	 * sqlId : 描述：分页Select
	 */
	public static final String sqlId_splitPageSelect = "sys.right.splitPageSelect";

	/**
	 * sqlId : 描述：分页from
	 */
	public static final String sqlId_splitPageFrom = "sys.right.splitPageFrom";

	/**
	 * sqlId : 描述：查询根节点
	 */
	public static final String sqlId_rootNode = "sys.right.rootNode";

	/**
	 * sqlId : 描述：根据上级节点id查询子部门信息
	 */
	public static final String sqlId_childNode = "sys.right.childNode";

	/**
	 * sqlId : 描述：统计节点下功能数
	 */
	public static final String sqlId_rightCount = "sys.right.rightCount";

	/**
	 * sqlId : 描述：根据上级节点id查询子节点数量
	 */
	public static final String sqlId_childCount = "sys.right.childCount";

	/**
	 * 添加或者更新缓存
	 */
	public static void cacheAdd(String ids) {
		Right right = Right.dao.findById(ids);
		ToolCache.set(ParamInitPlugin.cacheStart_right + ids, right);
		ToolCache.set(ParamInitPlugin.cacheStart_right + right.getStr(column_uri), right);
	}

	/**
	 * 删除缓存
	 * 
	 * @param ids
	 */
	public static void cacheRemove(String ids) {
		Right right = Right.dao.findById(ids);
		ToolCache.remove(ParamInitPlugin.cacheStart_right + ids);
		ToolCache.remove(ParamInitPlugin.cacheStart_right + right.getStr(column_uri));
	}

	/**
	 * 获取缓存
	 * 
	 * @param key
	 * @return
	 */
	public static Right cacheGet(String key) {
		Right right = ToolCache.get(ParamInitPlugin.cacheStart_right + key);
		if (right == null) {
			right = Right.dao.findById(key);
			if (right == null) {
				String sql = getSqlMy(sqlId_uri);
				right = Right.dao.findFirst(sql, key);
			}
		}
		return right;
	}
	
	/**
	 * 获取父节点
	 * @return
	 */
	public Right getParent(){
		return cacheGet(this.getStr(Right.column_parentids));
	}

}
